<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/assets/layui_select/formSelects-v4.css">
</head>

<body layadmin-themealias="default">

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" pad15="">

                        <div class="layui-form" lay-filter="">
                            <input type="hidden" name="id" value="{$userinfo.id}">

                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">用户名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" value="{$userinfo.account}" disabled placeholder="请输入用户名..."
                                            class="layui-input" />
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">用户ID</label>
                                    <div class="layui-input-inline">
                                        <input type="text" value="{$userinfo.id}" disabled placeholder="请输入..."
                                            class="layui-input" />
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">手机号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="" value="{$userinfo.mobile}" readonly disabled
                                            placeholder="请输入手机号..." class="layui-input" />
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">密码</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="password" value="" class="layui-input" lay-verify="">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">昵称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="nick_name" value="{$userinfo.nick_name}"
                                            class="layui-input" lay-verify="" />
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">头像</label>
                                    <div class="layui-input-inline" style="width: 65px;">
                                        <div class="layui-upload">
                                            <div class="layui-upload-list" style="margin:0px">
                                                <img class="layui-upload-img" src="{$userinfo.avatar}" id="demo1"
                                                    width="55" height="55" />
                                                <p id="demoText"></p>
                                                <input type="hidden" name="avatar" id="LAY_avatarSrc" placeholder="图片地址"
                                                    value="{$userinfo.avatar}" class="layui-input" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                        <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatar">
                                            <i class="layui-icon">&#xe67c;</i>选择头像
                                        </button>
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item" {if $userinfo->account_type > 2} style="display:none"{/if} >
                                <div class="layui-inline">
                                    <label class="layui-form-label">账号类型</label>
                                    <div class="layui-input-inline">
                                        <select name="account_type" {if $userinfo->account_type > 2} disabled {/if}
                                            lay-filter="account_type">
                                            {foreach name="account_typearr" item="vo" key="k" }
                                            <option value="{$k}" {$k==$userinfo['account_type']?'selected':''}>{$vo}
                                            </option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">备注</label>
                                    <div class="layui-input-inline">
                                        <textarea class="layui-textarea" style="min-height:50px;" name="remark"
                                            placeholder="请输入备注..."></textarea>
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">竞猜权限</label>
                                    <div class="layui-input-inline">
                                        <input type="radio" name="is_guess_host" value="0" title="关闭" <?php if
                                            (isset($userinfo['is_guess_host']) &&
                                            $userinfo['is_guess_host']==0){echo 'checked' ;}?>>
                                        <input type="radio" name="is_guess_host" value="1" title="开启" <?php if
                                            (isset($userinfo['is_guess_host']) &&
                                            $userinfo['is_guess_host']==1){echo 'checked' ;}?>>
                                    </div>
                                </div>
                                {if $userinfo->expert_type == 0}
                                <div class="layui-inline">
                                    <label class="layui-form-label">专家角色</label>
                                    <div class="layui-input-inline">
                                        <select name="expert_type">
                                            <option value="">请选择</option>
                                            <option value="1">专家</option>
                                            <option value="2">测试专家</option>
                                        </select>
                                    </div>
                                </div>
                                {/if}
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">直播回放</label>
                                    <div class="layui-input-inline">
                                        <input type="radio" name="replay_show" value="0" title="关闭" <?php if
                                            (isset($userinfo['replay_show']) &&
                                            $userinfo['replay_show']==0){echo 'checked' ;}?>>
                                        <input type="radio" name="replay_show" value="1" title="开启" <?php if
                                            (isset($userinfo['replay_show']) &&
                                            $userinfo['replay_show']==1){echo 'checked' ;}?>>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">标签选择</label>
                                    <div class="layui-input-inline">
                                        <select name="tags" lay-filter="tags">
                                            <option value="">选择标签</option>
                                            {foreach name="tags" item="vo" key="k" }
                                            <option value="{$vo['id']}" {$vo['id']==$userinfo['tags']?'selected':''}>{$vo['title']}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item" id="sharingRatio"
                                {$userinfo.is_anchor==1?'':'style="display:none"'}>
                            <label class="layui-form-label">分成比例</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sharing_ratio" value="{$userinfo.sharing_ratio}" class="layui-input" lay-verify="" style="display: inline-block; width: 100px;">
                                %
                            </div>
                        </div>

                        <div class="layui-form-item" {$userinfo.is_anchor==1?'':' style="display:none"'}>
                            <label class="layui-form-label">私聊人员</label>
                            <div class="layui-input-block">
                                <select name="chat_admin_ids" xm-select="chat_admin_ids" xm-select-search="">
                                    {volist name="admin_list" id="vo"}
                                    <option value="{$vo.id}" {:in_array($vo.id,$userinfo.chat_admin_ids)?'
                                selected':''}>{$vo.id}-{$vo.name}</option>
                                {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-block">
                                <label class="layui-form-label">主播广告图</label>
                                <div class="layui-input-inline">
                                    <input name="banner" id="LAY_imgSrc" placeholder="请上传图片或输入地址"
                                        value="{$userinfo['banner']}" class="layui-input">
                                </div>
                                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                    <button type="button" class="layui-btn layui-btn-primary" id="LAY_imgUpload">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                </div>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <div class="layui-block">
                                <label class="layui-form-label">主播简介</label>
                                <div class="layui-input-block">
                                    <textarea name="intro" class="layui-textarea">{$userinfo['intro']}</textarea>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block text-center">
                                <button class="layui-btn" lay-submit="" lay-filter="user-edit">确认保存</button>
                                <button class="layui-btn layui-btn-primary" id="close">取消</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    </div>

    <script src="/layuiadmin/layui/layui.js"></script>
    <script src="/assets/cos-js-sdk-v5/cos-js-sdk-v5.min.js"></script>
    <script src="/assets/ue/third-party/jquery-1.10.2.js"></script>
    <script src="/assets/layui_select/formSelects-v4.min.js"></script>
    <script>
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index', //主入口模块
            formSelects: 'formSelects-v4'
        }).use(['index', 'user', 'form', 'admin', "laytpl", "upload", "element", 'formSelects'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin;

            var upload = layui.upload;
            var element = layui.element;

            var index = parent.layer.getFrameIndex(window.name);

            $('#close').on("click", function () {
                parent.layer.close(index);
            });


            var avatarSrc = $("#LAY_avatarSrc");
            //常规使用 - 普通图片上传
            var choosefile;
            var uploadInst = upload.render({
                elem: "#LAY_avatar",
                url: "/admin/user/signForCos", //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
                before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        choosefile = file;
                        $("#demo1").attr("src", result); //图片链接（base64）
                    });

                    element.progress("demo", "0%"); //进度条复位
                    layer.msg("上传中", { icon: 16, time: 0 });
                },
                done: function (res) {
                    //如果上传失败
                    if (res.code == 0) {
                        var cos = new COS({
                            getAuthorization: function (options, callback) {
                                var credentials = res.data.credentials;
                                callback({
                                    TmpSecretId: credentials.tmpSecretId,
                                    TmpSecretKey: credentials.tmpSecretKey,
                                    XCosSecurityToken: credentials.sessionToken,
                                    ExpiredTime: res.data.expiredTime,
                                });
                            },
                            Domain: res.data.imgDomain,
                        });
                        cos.putObject(
                            {
                                Bucket: res.data.bucket,
                                Region: res.data.region,
                                Key: "images/" + res.data.filename + choosefile.name,
                                Body: choosefile,
                            },
                            function (err, data) {
                                console.log(data);
                                layer.closeAll("loading");
                                if (err) {
                                    layer.msg("上传失败", { icon: 5 });
                                } else {
                                    if (data.statusCode == 200) {
                                        avatarSrc.val("https://" + data.Location);
                                        layer.msg("上传完毕", { icon: 1 });
                                    } else {
                                        layer.msg("图片上传失败", { icon: 5 });
                                    }
                                }
                            }
                        );
                    } else {
                        layer.closeAll("loading");
                        layer.msg(res.msg, { icon: 5 });
                    }
                    //上传成功的一些操作
                    //……
                    $("#demoText").html(""); //置空上传失败的状态
                },
                error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $("#demoText");
                    demoText.html(
                        '<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>'
                    );
                    demoText.find(".demo-reload").on("click", function () {
                        uploadInst.upload();
                    });
                },
                //进度条
                progress: function (n, elem, e) {
                    element.progress("demo", n + "%"); //可配合 layui 进度条元素使用
                    if (n == 100) {
                        // layer.msg('上传完毕', {icon: 1});
                    }
                },
            });

            form.on('select(account_type)', function (obj) {
                //提交
                if (obj.value == 3 || obj.value == 5) {
                    $('#sharingRatio').show();
                    return;
                }
                $('#sharingRatio input').val(0)
                $('#sharingRatio').hide()
            });


            form.on('submit(user-edit)', function (obj) {
                //提交
                layer.load();
                admin.req({
                    url: '/admin/user/edit_post'
                    , data: obj.field
                    , success: function (res) {
                        layer.closeAll("loading");
                        if (res.code == 0) {
                            parent.layer.close(index);
                            parent.layer.msg(res.msg, { icon: 1 });
                            parent.layui.table.reload('LAY-user-manage');
                        }
                    }
                    , complete: function (res) {
                        layer.closeAll("loading");
                    }
                });
                return false;
            });

            //上传图标
            var imgSrcSem = $('#LAY_imgSrc');
            upload.render({
                url: '/admin/index/noOperation',
                elem: '#LAY_imgUpload',
                auto: true,
                accept: 'images',
                exts: 'svg|png|jpg|jpeg|gif|webpg',
                size: 1024 * 1024 * 5,
                choose: function (obj) {
                    layer.load();
                    var choosefile;
                    obj.preview(function (index, file, result) {
                        choosefile = file;
                    });
                    admin.req({
                        url: '/admin/ads/signForCos'
                        , success: function (res) {
                            if (res.code == 0) {
                                var cos = new COS({
                                    getAuthorization: function (options, callback) {
                                        var credentials = res.data.credentials;
                                        callback({
                                            TmpSecretId: credentials.tmpSecretId,
                                            TmpSecretKey: credentials.tmpSecretKey,
                                            XCosSecurityToken: credentials.sessionToken,
                                            ExpiredTime: res.data.expiredTime
                                        });
                                    },
                                    Domain: res.data.imgDomain,
                                });
                                cos.putObject({
                                    Bucket: res.data.bucket,
                                    Region: res.data.region,
                                    Key: 'images/' + res.data.filename + choosefile.name,
                                    Body: choosefile,
                                }, function (err, data) {
                                    layer.closeAll('loading');
                                    if (err) {
                                        layer.msg("上传失败", { icon: 5 });
                                    } else {
                                        if (data.statusCode == 200) {
                                            imgSrcSem.val("https://" + data.Location);
                                        } else {
                                            layer.msg("图片上传失败", { icon: 5 });
                                        }
                                    }
                                });
                            } else {
                                layer.closeAll('loading');
                                layer.msg(res.msg, { icon: 5 });
                            }
                        }
                    })
                }
            });
        });
    </script>
</body>

</html>